<template>
	<div class="shopm">
		<view class="weui-cells__title">店铺名</view>
		<div class="weui-cells weui-cells_after-title">
			<view class="weui-cell weui-cell_input">
				
				<view class="weui-cell__bd">
					<input class="weui-input" placeholder="请输入店铺名" v-model="title" />
				</view>
			</view>
		</div>
		<view class="weui-cells__title">店铺简介</view>
		<div class="weui-cells weui-cells_after-title">
			<view class="weui-cell">
				
				<view class="weui-cell__bd">
					<textarea class="weui-textarea" placeholder="请输入简介" style="height: 3.3em" v-model="description" />
					<view class="weui-textarea-counter">0/200</view>
				</view>
			</view>
		</div>
		<div class="weui-cells__title nobott">花店宣传照</div>
		<!--<img src="" alt="" mode="widthFix" v-if="orderdetail && orderdetail!=''" />-->
		<img :src="banner" class="nopic" @click="shoppic()" mode="widthFix">
		

		<button class="submit" @click="submit">点击上传</button>
	</div>
</template>

<script>
	import { requests } from "../../../static/js/network"
	export default {
		data() {
			return {
				orderdetail: {},
				title: '',
				description: '',
				banner: ''
			}
		},
		onLoad() {
			let self = this
			requests({
				url: 'https://tp5.blver.cn/api/wechat/getFxStoreInfo',
				method: 'POST',
				header: {
					'content-type': 'application/json',
					'content-type': 'application/x-www-form-urlencoded' // 默认值
				},
				data: {

					session3rd: wx.getStorageSync('userinfo').session3rd
				},
				success: function(res) {
					console.log(res)
				
					self.banner=res.data.data.banner
					self.description=res.data.data.description
					self.title=res.data.data.title
					//self.content=self.classlist[0].goods_content.replace(/"\/static/g, '"https://tp5.blver.cn/static').replace(/"\/static/g, '"https://tp5.blver.cn/static').replace(/\<img/gi, '<img style="max-width:100%;height:auto" ')
				}
			})
		},
		methods: {

			shoppic() {
				
				var that = this;
				wx.chooseImage({
					sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
					success: function(res) {
						var tempFilePaths = res.tempFilePaths
						wx.uploadFile({
							url: `https://tp5.blver.cn/api/wechat/imgUpload`,
							filePath: tempFilePaths[0],
							name: 'file',

							formData: {
								//和服务器约定的token, 一般也可以放在header中
								banner:tempFilePaths[0],
								session3rd: wx.getStorageSync('userinfo').session3rd
							},
							header: {  
					            "Content-Type": "multipart/form-data" ,
					           
					          },
							success: function(res3) {
								console.log(res3)
									console.log(JSON.parse(res3.data))
									that.banner=JSON.parse(res3.data).data
							}
						})

					}
				})
			},

			submit() {
				let self = this
				let code = {
					title: self.title,
					description: self.description,
					banner: 'xxxx',
					session3rd: wx.getStorageSync('userinfo').session3rd
				}
				console.log(code)

				requests({
					url: 'https://tp5.blver.cn/api/wechat/setFxStoreInfo',
					method: 'POST',
					header: {
						'content-type': 'application/json',
						'content-type': 'application/x-www-form-urlencoded' // 默认值
					},
					data: {
						title: self.title,
						description: self.description,
						banner: self.banner,
						session3rd: wx.getStorageSync('userinfo').session3rd
					},
					success: function(res) {

						if(res.data.status == 'error') {
							wx.showToast({
								title: res.data.msg,
								icon: 'none',
								duration: 3000
							});
							return
						}
						wx.navigateTo({//保留当前页面，跳转到应用内的某个页面
							url: "/pages/myshop/main"
						})
						//self.orderdetail=res.data.data

						//self.content=self.classlist[0].goods_content.replace(/"\/static/g, '"https://tp5.blver.cn/static').replace(/"\/static/g, '"https://tp5.blver.cn/static').replace(/\<img/gi, '<img style="max-width:100%;height:auto" ')
					}
				})
			}
		}
	}
</script>

<style scoped>
	.nopic {
		
		color: #444444;
		width: 97vw;
		margin: 0 auto;
		border: 6px solid #fff;
		height: 300rpx;
		line-height: 300rpx;
		text-align: center;
	}
	
	.shopm {
		
		height: 100vh;
	}
	
	.weui-cells_after-title {
		border-bottom: 20rpx solid #ccc;
	}
	
	.weui-cells__title {
		background: #fff;
		padding: 20rpx;
	}
	
	.submit {
		position: fixed;
		bottom: 0;
		width: 100%;
	}
	
	.nobott {
		margin-bottom: 0;
	}
</style>